package com.neusoft.neuiotms.dcam.fixed.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.neuiotms.dcam.fixed.dto.AssetExtFieldConfigDTO;
import com.neusoft.neuiotms.dcam.fixed.service.AssetExtFieldConfigService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "资产固定扩展属性管理")
@RestController
@RequestMapping(value = "/api/w/assetExtFieldConfig")
public class AssetExtFieldConfigController {

    @Autowired
    private AssetExtFieldConfigService assetExtFieldConfigService;

    @ApiOperation("查询所有扩展属性")
    @GetMapping
    public ResultListDTO<AssetExtFieldConfigDTO> index() {
        final List<AssetExtFieldConfigDTO> DTOs = this.assetExtFieldConfigService.findAll();
        final ResultListDTO<AssetExtFieldConfigDTO> result = ResultListDTO.success(DTOs);
        return result;
    }

    @ApiOperation("查询有效所有扩展属性")
    @GetMapping("/effective")
    public ResultListDTO<AssetExtFieldConfigDTO> findEffective() {
        final List<AssetExtFieldConfigDTO> DTOs = this.assetExtFieldConfigService.findEffective();
        final ResultListDTO<AssetExtFieldConfigDTO> result = ResultListDTO.success(DTOs);
        return result;
    }

    @ApiOperation("创建扩展属性")
    @PostMapping
    public ResultDTO<AssetExtFieldConfigDTO> create(@RequestBody final AssetExtFieldConfigDTO dto) {
        final AssetExtFieldConfigDTO result = this.assetExtFieldConfigService.create(dto);
        return ResultDTO.success(result);
    }

    @ApiOperation(value = "修改扩展属性")
    @PutMapping("/{id}")
    public ResultDTO<AssetExtFieldConfigDTO> update(@PathVariable final Long id,
            @RequestBody final AssetExtFieldConfigDTO dto) {
        final AssetExtFieldConfigDTO result = this.assetExtFieldConfigService.update(id, dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("扩展属性详情")
    @GetMapping("/{id}")
    public ResultDTO<AssetExtFieldConfigDTO> details(@PathVariable final Long id) {
        final AssetExtFieldConfigDTO dto = this.assetExtFieldConfigService.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("删除扩展属性")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.assetExtFieldConfigService.delete(id);
        return ResultDTO.success();
    }

}
